package bg.cinema_system.service;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import bg.cinema_system.DAO.ReservationDAO;
import bg.cinema_system.DAO.SeatDAO;

public class ReservationService {

	public static List<Integer> getReservedSeats(int projection_id) throws SQLException {
		return ReservationDAO.getReservedSeats(projection_id);
	}
	
	public static List<Integer> getPaidSeats(int projection_id) throws SQLException {
		return ReservationDAO.getPaidSeats(projection_id);
	}
	
	
	public static boolean makeReservation(List<Integer> seat_numbers, int projection_id, int user_id, Date expires_at) throws SQLException {
		
		boolean made = ReservationDAO.makeReservation(user_id, projection_id, expires_at);
		
		int reserv_id = -1;
		int hall_id = -1;
		
		if (made) {
			reserv_id = ReservationDAO.getReservationId(projection_id, user_id);
			hall_id = ProjectionService.getHallID(projection_id);
			for (int seat_nb : seat_numbers) {
				SeatDAO.reserveSeat(seat_nb, hall_id, reserv_id);
			}
		}
		
		return made;
	}
}
